package com.woniuxy.driverschool.controller;

import com.github.pagehelper.util.StringUtil;
import com.mysql.jdbc.StringUtils;
import com.woniuxy.driverschool.entity.*;
import com.woniuxy.driverschool.service.StudyTimeService;
import com.woniuxy.driverschool.service.impl.StudyTimeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author: xyq
 * @version: 1.0.0
 * @create: 2021/10/11 17:49
 * @description: TODO
 */
@RestController
@RequestMapping()
public class StudyTimeController {

    @Autowired
    StudyTimeService studyTimeService;

    private static final String CONTROLLER_MAPPING = "studyTime";

    /**
     *
     * @param pageIndex
     * @param pageSize
     * @param startTime
     * @param endTime
     * @return
     */
    //查询学员学时
    @GetMapping(CONTROLLER_MAPPING +"/list/page")
    public ResponseResult<PageBean<StudyTime>> getStudyTime( StudyTime studyTime, Student student,int pageIndex, int pageSize,
                                                            String startTime, String endTime) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
        Date startTime1 = null;
        Date endTime1 = null;
        if(!(null == startTime || "".equals(startTime))) {
            startTime1 = sdf.parse(startTime);
        }
        if(!(null == endTime || "".equals(endTime))) {
            endTime1 = sdf.parse(endTime);
        }
//        System.out.println("查询条件：" + sname);
//        System.out.println("查询条件：" + packageName);
//        System.out.println("查询条件：" + carType);
        studyTime.setStudent(student);
        System.out.println("pageSize：" + pageSize);
        System.out.println("pageIndex：" + pageIndex);
        int selectCountStudyTimeByPage = studyTimeService.selectCountStudyTimesByPage(studyTime, startTime1, endTime1);
        List<StudyTime> studyTimes = studyTimeService.selectAllStudyTimesByPage(studyTime, pageIndex, pageSize, startTime1, endTime1);
        PageBean<StudyTime> pageBean = new PageBean<StudyTime>();
        pageBean.setBeanList(studyTimes);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(selectCountStudyTimeByPage);
        return new ResponseResult<PageBean<StudyTime>>(pageBean, 200, "ok");
    }

}